<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.icss.th.subjects.pojo.Subject"%>
<%@ page import="com.icss.th.subjects.service.SubjectService"%>
<%@ page import="com.icss.th.common.Constants.SEARCH_TYPE"%>
<%
	String context = request.getContextPath();
%>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>题海——考试、复习的最佳助手</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<link href="<%=context%>/includes/css/base.css" rel="stylesheet" />
<script src="<%=context%>/includes/js/jquery.cookie.js"></script>
</head>

<body>
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
  <div class="navbar-header">
    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse"> <span class="sr-only">TIHAI</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button>
    <a class="navbar-brand tihai-logo" href="/">&nbsp;</a> </div>
  <div class="collapse navbar-collapse navbar-ex1-collapse hidden">
    <ul class="nav navbar-nav navbar-right">
      <li><a href="#" data-toggle="modal1" data-target="#login-modal">登录</a></li>
      <li class="divider-vertical"></li>
      <li><a href="#" data-toggle="modal1" data-target="#signup-modal">注册</a></li>
    </ul>
  </div>
</nav>
<div class="container" >
    <input type="hidden" value="" id="subjectId" name="subjectId">
    <div class="row">
      <h4 >检索题库：<span id="subjectName" ></span>
        <button type="button"  class="btn btn-xs btn-default" style="margin-left:10px;"  data-toggle="collapse" data-target="#subj"><!--<span class="glyphicon glyphicon-chevron-down"></span>-->更改</button>
      </h4>
    </div>
    <%
		Subject root = SubjectService.getRoot();
		if (root != null)
		{
			List<Subject> list = root.getChildren();
			if (list  != null && !list.isEmpty())
			{
	%>
    <div class="row" >
      <div  id="subj" class="collapse in_del">
        <div class="Classification" >
          <div class="panel panel-default">
            <div class="panel-heading" id="sl">
            	<%
            		List<Subject> popularList = SubjectService.getPopular(10);
            		if (popularList != null && !popularList.isEmpty())
            		{
            	%>
            	<strong style="padding-left:20px">热门考试：
            	<%
            		for (Subject sub : popularList)
            		{
            	%>
            		<a id="<%=sub.getId()%>"><%=sub.getName()%></a> |
            	<%} %>
            	</strong></div>
            	<%} %>
            <table class="table">
            <%
				for (int i = 0; i < list.size(); i++)
				{
					Subject level1 = list.get(i);
			%>
              <tr>
                <th><%=level1.getName()%></th>
                <td id="sl">
                <%
					List<Subject> list2 = level1.getChildren();
					if (list2  != null && !list2.isEmpty())
					{
						for (Subject level2 : list2)
						{
				%>
                	<a id="<%=level2.getId()%>"><%=level2.getName()%></a> |  
                <%}} %>
                </td>
              </tr>
             <%} %>
            </table>
          </div>
        </div>
      </div>
    </div>
    <%} }%>
    <div class="row" >
      <div class="form-group">
        <label for="keyword">使用以下条件进行题库检索</label>
        <input  type="text"  class="form-control input-lg" placeholder="输入试题题目或者关键词" maxlength="38"  id="keyword"  name="keyword" x-webkit-speech="x-webkit-speech" required />
      </div>
      <div class="form-group">
        <label for="keyword">不包括以下任何字词</label>
        <input  type="text"  class="form-control input-lg" placeholder="输入试题题目或者关键词" maxlength="38"  id="unkeyword"  name="unkeyword" x-webkit-speech="x-webkit-speech" required />
      </div>
      <div class="form-group">
        <label for="qt">搜索题目质量</label>
        <select id="qt" multiple class="form-control disabled" disabled>
          <option selected>全部题海题库</option>
          <option>国家级考试题库</option>
          <option>高质量试题级</option>
          <option>三年内题库</option>
          <option>最近一个月题库</option>
        </select>
      </div>
      <br/>
      <button class="btn  btn-primary"  onclick="_search(<%=SEARCH_TYPE.QUESTION%>)" > 搜 试 题 </button>
      &nbsp;  &nbsp;
      <button class="btn  btn-default"  onclick="_search(<%=SEARCH_TYPE.PAPER%>)"> 查 试 卷 </button>
      <br>
      <br>
    </div>
    <div class="text-right"><a href="app.html" target="_blank">手机应用</a> &nbsp; &nbsp; <a  href="index.html" target="_self">普通搜索</a></div>
</div>
<div id="ftCon" class="container">
  <p><a onclick="AddFavorite()" href="#">加入收藏夹</a> <a target="_blank" href="http://wpa.qq.com/msgrd?v=3&uin=1003753463&site=qq&menu=yes"><img border="0" src="http://wpa.qq.com/pa?p=2:1003753463:51" alt="点击这里给我发消息" title="点击这里给我发消息"/></a> </p>
  <p><a href="aboutus.html" target="_blank">关于我们</a>&nbsp; | &nbsp; <a href="joinus.html" target="_blank">参与题海项目（众包）</a>&nbsp; |  &nbsp; <a  class="disabled" target="_blank">开放接口</a> </p>
  <p> &copy;2013&nbsp;Tihai.org&nbsp;北京题海科技有限公司&nbsp;&nbsp;<a href="#">使用必读</a>&nbsp;&nbsp;&nbsp; <a   href="#">冀ICP备08007478号</a>&nbsp; </p>
</div>
<script>
$("#keyword").keypress(function(event){
	if ( event.which == 13 ) {
		_search(<%=SEARCH_TYPE.QUESTION%>);
	}
});

$("#unkeyword").keypress(function(event){
	if ( event.which == 13 ) {
		_search(<%=SEARCH_TYPE.QUESTION%>);
	}
});

$(function(){
	$("#subjectName").html($.cookie('subjectName')? $.cookie('subjectName') : '请选择检索题库 →');
	$("#subjectId").val($.cookie('subjectId')? $.cookie('subjectId') : '');
});

function _search(type){
	if ($.trim($("#keyword").val()) && $.trim($("#subjectId").val())){
		$.cookie('subjectId', $("#subjectId").val(), {path:'/'});
		$.cookie('subjectName', $("#subjectName").html(), {path:'/'});
		
		var path = '<%=context%>/adsearch?';
		path += 'subjectId=' + $("#subjectId").val();
		path += '&type=' + type;
		path += '&keyword=' + encodeURI(encodeURI($("#keyword").val()));
		path += '&unkeyword=' + encodeURI(encodeURI($("#unkeyword").val()));
		location.href = path;
	}else{
		location.reload();
	}
}

 $('#sl a').click(function(){
	$("#subjectId").val($(this).attr('id'));
	$("#subjectName").html($(this).text());
	$("#subj").collapse('hide');
});
 
 function AddFavorite(){
		var sURL = window.location;
		var sTitle = document.title;
	    try{
	        window.external.addFavorite(sURL, sTitle);
	    }catch (e){
	        try{
	            window.sidebar.addPanel(sTitle, sURL, "");
	        }catch (e){
	            alert("加入收藏失败，请使用Ctrl+D进行添加");
	        }
	    }
	}
</script>
</body>
</html>
